package com.mall.web.control.weishang;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.mall.biz.trade.TradeBizImpl;
import com.mall.biz.user.AddressBizImpl;
import com.mall.biz.user.record.MallItemRecordBizImpl;
import com.mall.client.item.ItemCategoryService;
import com.mall.client.item.MallItemService;
import com.mall.client.mall.MallService;
import com.mall.client.order.MallItemOrderService;
import com.mall.client.trade.TradeService;
import com.mall.client.user.LogisticsService;
import com.mall.client.user.UserLevelService;
import com.mall.client.user.UserService;
import com.mall.common.util.PageUtil;
import com.mall.constant.UserConstant;
import com.mall.enums.AddressEnum;
import com.mall.pojo.Address;
import com.mall.pojo.ItemCategory;
import com.mall.pojo.Logistics;
import com.mall.pojo.Mall;
import com.mall.pojo.MallItem;
import com.mall.pojo.MallItemOrder;
import com.mall.pojo.Trade;
import com.mall.pojo.User;
import com.mall.pojo.UserLevel;
import com.mall.query.Page;
import com.mall.query.TradeRecordQuery;
import com.mall.vo.item.MallItemVO;
import com.mall.vo.trade.TradeVO;
import com.mall.web.annotation.AdminSecurity;
import com.mall.web.annotation.MaidianSecurity;
import com.mall.web.util.APPCookieUtil;
import com.mall.web.util.HttpUtil;
import com.mall.web.util.SplitUtil;
import com.mall.web.util.WebUtil;
import com.mall.web.vo.ResponseEntity;
/**
 * 合伙人系统订单操作
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/maidian/trade")
public class WeishangTradeController {
	
	private static final Logger log = LoggerFactory.getLogger(WeishangTradeController.class);
	
	@Autowired
	private TradeService tradeService;
	@Autowired
	private MallItemOrderService mallItemOrderService;
	@Autowired
	private MallItemService mallItemService;
	@Autowired
	private MallService mallService;
	@Autowired
	private ItemCategoryService itemCategoryService;
	@Autowired
	private TradeBizImpl tradeBizImpl;
	@Autowired
	private UserLevelService userLevelService;
	@Autowired
	private AddressBizImpl addressBizImpl;
	@Autowired
	private MallItemRecordBizImpl mallItemRecordBiz;
	@Autowired
	private LogisticsService logisticsService;
	@Autowired
	private UserService userService;
	/**
	 * 下单页面
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("order")
	@MaidianSecurity
	public String order(HttpServletRequest request,HttpServletResponse response,ModelMap modelMap){
		Integer onlyKey = HttpUtil.getCommkeyId(request, response);
		User user = WebUtil.getCurrentUser(request);
		List<Address> addressList = this.addressBizImpl.getAddressListByUserAndstatus(user.getId(), onlyKey, null, AddressEnum.DEFAULTADDRESS.getCode());
		Address address = this.addressBizImpl.getFirstAddress(addressList);//取分销商默认收货地址
		Long mallItemOrderId = HttpUtil.getLongValueFromRequest(request, "mallItemOrderId");
		MallItemOrder mallItemOrder = mallItemOrderService.getMallItemOrderById(mallItemOrderId);
		String itemJson = mallItemOrder.getBuyItemsJson();
		List<MallItemVO> mallItemVOList = null;
		if (itemJson != null) {
			mallItemVOList = JSONArray.parseArray(itemJson, MallItemVO.class);
		}
		UserLevel userLevel = this.userLevelService.getUserLevelByLevelAndKey(user.getLevel().intValue(), onlyKey);
		Long orPrice = mallItemOrder.getPrice()+mallItemOrder.getDiscountPrice();
		modelMap.put("orPrice", orPrice);
		modelMap.put("user", user);
		modelMap.put("userLevel", userLevel);
		modelMap.put("address", address);
		modelMap.put("price", mallItemOrder.getDiscountPrice());
		modelMap.put("mallItemVOList", mallItemVOList);
		modelMap.put("mallItemOrder", mallItemOrder);
		return "weishang/trade/order";
		
	}
	/**
	 * 下单接口
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@MaidianSecurity
	@RequestMapping("orderAction")
	public String orderAction(HttpServletRequest request,HttpServletResponse response,ModelMap modelMap){
		User user = WebUtil.getCurrentUser(request);
//		Long tableNumId = HttpUtil.getLongValueFromRequest(request, "tableNumId");
		Long addressId = HttpUtil.getLongValueFromRequest(request, "addressId");
		Long mallId = HttpUtil.getLongValueFromRequest(request, "mallId");
		Mall mall = this.mallService.getMallById(mallId);
		if(mall == null){
			return null;
		}
		MallItemOrder mallItemOrder = new MallItemOrder();

		Long mallItemOrderId = HttpUtil.getLongValueFromRequest(request, "mallItemOrderId");
		if (mallItemOrderId != null) {
			mallItemOrder = mallItemOrderService.getMallItemOrderById(mallItemOrderId);
		}
//		Integer mealNum = HttpUtil.getIntegerValueFromRequest(request, "mealNum");// 用餐人数
		String mallItemIds[] = request.getParameterValues("spId");//商品对应的id
		String nums[] = request.getParameterValues("spNum");// 商品对应的数量
		long price = 0l;
		if (mallItemIds != null && nums != null && mallItemIds.length > 0 && nums.length > 0
				&& mallItemIds.length == nums.length) {
			List<MallItemVO> mallItemVOList = new ArrayList<>();
			MallItemVO mallItemVO = null;
			Integer itemCounts = 0;
			// long price = 0l;
			for (int i = 0; i < mallItemIds.length; i++) {
				Long mallItemId = Long.parseLong(mallItemIds[i]);
				Integer waimaiNo = Integer.parseInt(nums[i]);
				MallItem mallItem = mallItemService.getMallItemById(mallItemId);
				ItemCategory itemCategory = this.itemCategoryService.getItemCategoryById(mallItem.getItemCategoryId());
				mallItemVO = new MallItemVO();
				if (itemCategory == null) {
					mallItemVO.setCategoryName("其他");
				} else {
					mallItemVO.setCategoryName(itemCategory.getItemCategoryName());
				}
				mallItemVO.setMallItemId(mallItem.getId());
				mallItemVO.setNo(waimaiNo);
				mallItemVO.setMallItemTitle(mallItem.getTitleName());
				BigDecimal show = (new BigDecimal(mallItem.getPrice().longValue())).divide(new BigDecimal(100));
				mallItemVO.setPrice(show.doubleValue() + "");
				mallItemVO.setPic(SplitUtil.convertStrToArray(mallItem.getMainPic(), 0));
				mallItemVOList.add(mallItemVO);
				itemCounts += waimaiNo;
				price = price + mallItem.getPrice() * waimaiNo;
			}
			String json = JSONArray.toJSONString(mallItemVOList);
			mallItemOrder.setBuyItemsJson(json);
			mallItemOrder.setBuyCount(itemCounts);
			mallItemOrder.setPrice(price);
		}

		mallItemOrder.setBuyUserId(user.getId());
		
		mallItemOrder.setTableNumId(addressId);
//		if (tableNumId == null) {
//			mallItemOrder.setTableNumId(0l);
//		} else {
//			mallItemOrder.setTableNumId(tableNumId);
//		}
//		mallItemOrder.setMealNum(mealNum);
		mallItemOrder.setMallId(mallId);
		mallItemOrder.setStatus(0);
		mallItemOrder.setGmtCreate(new Date());
		if (mallItemOrderId != null) {
			mallItemOrder.setGmtModify(new Date());
			this.mallItemOrderService.modifyMallItemOrder(mallItemOrder);
		} else {
			mallItemOrder.setGmtModify(new Date());
			this.mallItemOrderService.insertMallItemOrder(mallItemOrder);
		}

		Long orderId = mallItemOrder.getId();
		if (orderId == null || orderId == 0) {
			log.error("生成订单失败");
			return "redirect:/weishang/result/error.htm";
		}
		if(mallItemOrderId == null || mallItemOrderId <=0){
			return "redirect:/weishang/trade/order.htm?mallItemOrderId="+orderId;
		}else{
			return "redirect:/weishang/trade/pay.htm?mallItemOrderId="+orderId;
		}
		
	}
	/**
	 * 供应商的订单列表
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("indexTradeList")
	@MaidianSecurity
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public String indexTradeList(HttpServletRequest request,HttpServletResponse response,ModelMap modelMap){
		Integer status = HttpUtil.getIntegerValueFromRequest(request, "status");
		indexTradeMap(request, response, modelMap,status,null);
		return "weishang/trade/indexTradeList";
		
	}
	
	@RequestMapping("indexTradeListWeifukuan")
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public String indexTradeListWeifukuan(HttpServletRequest request,HttpServletResponse response,ModelMap modelMap){
		Integer status = HttpUtil.getIntegerValueFromRequest(request, "status");
		Integer refund = HttpUtil.getIntegerValueFromRequest(request, "refund");
		indexTradeMap(request, response, modelMap,status,refund);
		return "weishang/trade/include/indexTradeListWeifukuan";
		
	}
	/**
	 * 加载更多
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("indexTradeListMore")
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public String indexTradeListMore(HttpServletRequest request,HttpServletResponse response,ModelMap modelMap){
		Integer status = HttpUtil.getIntegerValueFromRequest(request, "status");
		indexTradeMap(request, response, modelMap,status,null);
		return "weishang/trade/indexTradeListMore";
		
	}
	/**
	 * 供应商的全部未发货
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("gysFahuoList")
	@MaidianSecurity
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public String gysFahuoList(HttpServletRequest request,HttpServletResponse response,ModelMap modelMap){
		Integer status = 1;
		indexTradeMap(request, response, modelMap,status,null);
		return "weishang/trade/gysFahuoList";
		
	}
	/**
	 * 供应商的全部为退款的
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("gysRefundList")
	@MaidianSecurity
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public String gysRefundList(HttpServletRequest request,HttpServletResponse response,ModelMap modelMap){
		Integer status = 4;
		Integer refund = 2;//用户申请退款过的
		indexTradeMap(request, response, modelMap,status,refund);
		return "weishang/trade/gysRefundList";
		
	}


	
	
	
	
	
	/**
	 * 分销商商品订单列表
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("tradeList")
	@MaidianSecurity
	public String tradeList(HttpServletRequest request,HttpServletResponse response,ModelMap modelMap){
		tradeMap(request, response, modelMap);
		return "weishang/trade/tradeList";
		
	}
	/**
	 * 加载更多
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("tradeListMore")
	@MaidianSecurity
	public String tradeListMore(HttpServletRequest request,HttpServletResponse response,ModelMap modelMap){
		tradeMap(request, response, modelMap);
		return "weishang/trade/tradeListMore";
		
	}
	/**
	 * 订单详情
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("orderDetail")
	@MaidianSecurity
	public String tradeDetail(HttpServletRequest request,HttpServletResponse response,ModelMap modelMap){
		Integer onlyKey = HttpUtil.getCommkeyId(request, response);
		Long tradeId = HttpUtil.getLongValueFromRequest(request, "tradeId");
		Trade trade = this.tradeService.getTradeByOrderId(tradeId);
		MallItemOrder mallItemOrder = this.mallItemOrderService.getMallItemOrderById(trade.getParentId());
		String itemJson = mallItemOrder.getBuyItemsJson();
		List<MallItemVO> mallItemVOList = null;
		if (itemJson != null) {
			mallItemVOList = JSONArray.parseArray(itemJson, MallItemVO.class);
		}
		User currentUser = WebUtil.getCurrentUser(request);
		User user = null;
		if(UserConstant.TYPE_MANAGE == currentUser.getType()){
			Long userId = HttpUtil.getLongValueFromRequest(request, "userId");
			user = this.userService.getUserByUserId(userId);
		}else{
			user = currentUser;
		}
		UserLevel userLevel = this.userLevelService.getUserLevelByLevelAndKey(user.getLevel().intValue(), onlyKey);
		List<Address> addressList = this.addressBizImpl.getAddressListByUserAndstatus(user.getId(), onlyKey, null, AddressEnum.DEFAULTADDRESS.getCode());
		Address address = this.addressBizImpl.getFirstAddress(addressList);
		modelMap.put("currentUser", currentUser);
		modelMap.put("user", user);
		modelMap.put("userLevel", userLevel);
		modelMap.put("address", address);
		modelMap.put("mallItemOrder", mallItemOrder);
		modelMap.put("trade", trade);
		modelMap.put("mallItemVOList", mallItemVOList);
		return "weishang/trade/orderDetail";
	}
	/**
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@MaidianSecurity
	@RequestMapping("wxpay")
	public String wxpay(HttpServletRequest request,HttpServletResponse response,ModelMap modelMap){
		Long orderId = HttpUtil.getLongValueFromRequest(request, "tradeId");
		return "redirect:/wxPay/auth.htm?orderId=" + orderId;
		
	}
	@MaidianSecurity
	@RequestMapping("opreateTradeJson")
	public ResponseEntity<Trade> opreateTradeJson(HttpServletRequest request,HttpServletResponse response){
		ResponseEntity<Trade>  responseEntity = new ResponseEntity<>();
		Integer status = HttpUtil.getIntegerValueFromRequest(request, "status");
		Long tradeId = HttpUtil.getLongValueFromRequest(request, "tradeId");
		Trade trade = this.tradeService.getTradeByOrderId(tradeId);
		if(trade == null){
			responseEntity.initErrorResponseEntity(null, "trade order error");
			return responseEntity;	
		}
		trade.setStatus(status);
		trade.setGmtModify(new Date());
		
		Integer result = this.tradeService.updateTradeByTrade(trade);
		if(result == null || result<=0){
			responseEntity.initErrorResponseEntity(null, "trade order error");
			return responseEntity;	
		}
		responseEntity.initSuccResponseEntity(trade, "success");
		return responseEntity;
		
	}
	@MaidianSecurity
	@RequestMapping("deleteTradeJson")
	@ResponseBody
	public ResponseEntity<Trade> deleteTradeJson(HttpServletRequest request,HttpServletResponse response){
		ResponseEntity<Trade>  responseEntity = new ResponseEntity<>();
		Long tradeId = HttpUtil.getLongValueFromRequest(request, "tradeId");
		Trade trade = this.tradeService.getTradeByOrderId(tradeId);
		if(trade == null){
			responseEntity.initErrorResponseEntity(null, "trade order error");
			return responseEntity;	
		}
		trade.setStatus(-1);
		trade.setGmtModify(new Date());
		
		Integer result = this.tradeService.updateTradeByTrade(trade);
		if(result == null || result<=0){
			responseEntity.initErrorResponseEntity(null, "trade order error");
			return responseEntity;	
		}
		responseEntity.initSuccResponseEntity(trade, "success");
		return responseEntity;
		
	}
	/**
	 * 用户确认收货
	 * @param request
	 * @param response
	 * @return
	 */
	@MaidianSecurity
	@RequestMapping("confirmReceiptAction")
	@ResponseBody
	public ResponseEntity<Boolean> confirmReceiptAction(HttpServletRequest request,HttpServletResponse response){
		ResponseEntity<Boolean>  responseEntity = new ResponseEntity<>();
		Integer onlyKey = HttpUtil.getCommkeyId(request, response);
		User user = WebUtil.getCurrentUser(request);
		Long tradeId = HttpUtil.getLongValueFromRequest(request, "tradeId");
		TradeRecordQuery tradeRecordQuery = new TradeRecordQuery();
		tradeRecordQuery.setOnlyKey(onlyKey);
		tradeRecordQuery.setUserId(user.getId());
		tradeRecordQuery.setStatus(4);
		Boolean  result = tradeBizImpl.updateTrade(tradeId,tradeRecordQuery);
		if(result == false){
			responseEntity.initErrorResponseEntity(false, "opearate error");
			return responseEntity;	
		}
		responseEntity.initSuccResponseEntity(true, "success");
		return responseEntity;
		
	}
	/**
	 * 供应商发货
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	
	@RequestMapping("sendOutGoods")
	@MaidianSecurity
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public String sendOutGoods(HttpServletRequest request,HttpServletResponse response,ModelMap modelMap){
		Long tradeId = HttpUtil.getLongValueFromRequest(request, "tradeId");
		modelMap.put("tradeId", tradeId);
		return "weishang/trade/sendOutGoods";
		
	}
	/**
	 * 确认发货接口
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	
	@RequestMapping("sendOutGoodsAction")
	@MaidianSecurity
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public String sendOutGoodsAction(HttpServletRequest request,HttpServletResponse response,ModelMap modelMap){
		Integer onlyKey = HttpUtil.getCommkeyId(request, response);
		Long tradeId = HttpUtil.getLongValueFromRequest(request, "tradeId");
		String logisticsCompany = HttpUtil.getStringValueFromRequest(request, "logisticsCompany");
		String logisticsId = HttpUtil.getStringValueFromRequest(request, "logisticsId");
		Trade trade = this.tradeService.getTradeByOrderId(tradeId);
		if (trade == null) {
			return "";
		}
		trade.setStatus(2);
		trade.setLogisticsCompany(logisticsCompany);
		trade.setLogisticsId(logisticsId);
		trade.setLogisticsStatus(2);
		Integer result = this.tradeService.updateTradeByTrade(trade);
		
		Logistics logistics = logisticsService.getLogisticsByLogisticsIdAndLogisticsCompany(logisticsId,
				logisticsCompany,onlyKey);
		if (logistics == null) {
			return "";
		}
		 
		if (result == null || result <=0) {
			return "";
		}
		return "redirect:/weishang/trade/gysFahuoList.htm";
		
	}
	/**
	 * 查看物流
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@MaidianSecurity
	@RequestMapping("logistics")
	public String logistics(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		
		Long tradeId = HttpUtil.getLongValueFromRequest(request, "tradeId");
		Trade trade = this.tradeService.getTradeByOrderId(tradeId);
		modelMap.put("trade", trade);
		return "weishang/trade/logistics";
		
	}
	/**
	 * 物流信息
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	
	@MaidianSecurity
	@RequestMapping("logisticsInfo")
	@ResponseBody
	public String logisticsInfo(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		Integer onlyKey = HttpUtil.getCommkeyId(request, response);
		String logisticsId = request.getParameter("logisticsId");
		String logisticsCompany = request.getParameter("logisticsCompany");
		if (StringUtils.isBlank(logisticsCompany) || StringUtils.isBlank(logisticsId)) {
			return "";
		}
		Logistics logistics = logisticsService.getLogisticsByLogisticsIdAndLogisticsCompany(logisticsId,
				logisticsCompany,onlyKey);
		if (logistics == null) {
			return "";
		}
		return logistics.getLogisticsAddress();

	}
	
	/**
	 * 用户申请退款
	 * @param request
	 * @param response
	 * @return
	 */
	@MaidianSecurity
	@RequestMapping("refundJson")
	@ResponseBody
	public ResponseEntity<Trade> refundJson(HttpServletRequest request,HttpServletResponse response){
		ResponseEntity<Trade>  responseEntity = new ResponseEntity<>();
		String refundReason = HttpUtil.getStringValueFromRequest(request, "refundReason");
		Long tradeId = HttpUtil.getLongValueFromRequest(request, "tradeId");
		Trade trade = this.tradeService.getTradeByOrderId(tradeId);
		if(trade == null){
			responseEntity.initErrorResponseEntity(null, "trade order error");
			return responseEntity;	
		}
		trade.setRefundReason(refundReason);
		trade.setRefund(2);//手动申请退款
		trade.setGmtModify(new Date());
		Integer result = this.tradeService.updateTradeByTrade(trade);
		if(result == null || result<=0){
			responseEntity.initErrorResponseEntity(null, "trade order error");
			return responseEntity;	
		}
		responseEntity.initSuccResponseEntity(trade, "success");
		return responseEntity;
		
	}
	
	
	/**
	 * 供应商确认给用户退款
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("confirmRefundJson")
	@MaidianSecurity
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	@ResponseBody
	public ResponseEntity<Trade> confirmRefundJson(HttpServletRequest request,HttpServletResponse response){
		ResponseEntity<Trade>  responseEntity = new ResponseEntity<>();
		Long tradeId = HttpUtil.getLongValueFromRequest(request, "tradeId");
		Trade trade = this.tradeService.getTradeByOrderId(tradeId);
		if(trade == null){
			responseEntity.initErrorResponseEntity(null, "trade order error");
			return responseEntity;	
		}
		trade.setRefund(4);//手动确认退款
		trade.setGmtModify(new Date());
		Integer result = this.tradeService.updateTradeByTrade(trade);
		if(result == null || result<=0){
			responseEntity.initErrorResponseEntity(null, "trade order error");
			return responseEntity;	
		}
		responseEntity.initSuccResponseEntity(trade, "success");
		return responseEntity;
		
	}


	
	/**
	 * 下单失败
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("orderError")
	public String orderError(HttpServletRequest request,HttpServletResponse response){
		
		return "weishang/trade/orderError";
	}
	
	/**
	 * 下单成功
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("orderSuccess")
	public String orderSuccess(HttpServletRequest request,HttpServletResponse response){
		
		return "weishang/trade/orderSuccess";
	}
	
	private  ModelMap indexTradeMap(HttpServletRequest request,HttpServletResponse response,ModelMap modelMap,Integer status,Integer refund){
		Page page = new Page();
		int pageNo = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "pageNo", 1);
		int pageSize = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "pageSize",PageUtil.PAGE_SIZE_APP);
		page.setPageByPageNoAndPageSize(pageNo, pageSize);
		Integer onlyKey = HttpUtil.getCommkeyId(request, response);
		
		TradeRecordQuery tradeRecordQuery = new TradeRecordQuery();
		tradeRecordQuery.setOnlyKey(onlyKey);
		tradeRecordQuery.setType(12);//trade表里type为12的
		tradeRecordQuery.setPage(page);
		tradeRecordQuery.setStatus(status);
		tradeRecordQuery.setRefund(refund);
		List<TradeVO> tradeVOList = this.mallItemRecordBiz.getTradeVOListByQuery(tradeRecordQuery);
		
	//	List<MallItemOrderVO> mallItemOrderVOList = this.mallItemRecordBiz.getMallItemOrderByQuery(tradeRecordQuery);
	//	modelMap.put("mallItemOrderVOList", mallItemOrderVOList);
		modelMap.put("tradeVOList", tradeVOList);
		int app = APPCookieUtil.urlFromApp(request);
		modelMap.put("app", app);
		User user = WebUtil.getCurrentUser(request);
		modelMap.put("user", user);
		modelMap.put("pageSize", pageSize);
		return modelMap;
		
	}
	
	private  ModelMap tradeMap(HttpServletRequest request,HttpServletResponse response,ModelMap modelMap){
		Page page = new Page();
		int pageNo = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "pageNo", 1);
		int pageSize = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "pageSize",PageUtil.PAGE_SIZE_APP);
		page.setPageByPageNoAndPageSize(pageNo, pageSize);
		Integer onlyKey = HttpUtil.getCommkeyId(request, response);
		Integer status = HttpUtil.getIntegerValueFromRequest(request, "status");
		TradeRecordQuery tradeRecordQuery = new TradeRecordQuery();
		tradeRecordQuery.setOnlyKey(onlyKey);
		tradeRecordQuery.setType(12);//trade表里type为12的
		tradeRecordQuery.setPage(page);
		tradeRecordQuery.setStatus(status);
		
		User user = WebUtil.getCurrentUser(request);
		if(user != null){
			tradeRecordQuery.setUserId(user.getId());
		}
		List<TradeVO> tradeVOList = this.mallItemRecordBiz.getTradeVOListByQuery(tradeRecordQuery);
		
	//	List<MallItemOrderVO> mallItemOrderVOList = this.mallItemRecordBiz.getMallItemOrderByQuery(tradeRecordQuery);
	//	modelMap.put("mallItemOrderVOList", mallItemOrderVOList);
		UserLevel userLevel = this.userLevelService.getUserLevelByLevelAndKey(user.getLevel().intValue(), onlyKey);
		modelMap.put("tradeVOList", tradeVOList);
		int app = APPCookieUtil.urlFromApp(request);
		modelMap.put("app", app);
		modelMap.put("user", user);
		modelMap.put("userLevel", userLevel);
		modelMap.put("status", status);
		modelMap.put("pageSize", pageSize);
		return modelMap;
		
	}
}
